package cn.anc.aonicardv.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import cn.anc.aonicardv.R;

/**
 * Created by yangdai on 2017/5/19.
 */

public class RecorderEditLayout extends LinearLayout {

    public TextView downloadTv;
    public TextView deleteTv;
    public TextView shareTv;
    public RelativeLayout downloadRl;
    public RelativeLayout deleteRl;
    public RelativeLayout shareRl;

    public RecorderEditLayout(Context context) {
        super(context);
    }

    public RecorderEditLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public RecorderEditLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
        View v = LayoutInflater.from(context).inflate(R.layout.pop_recorder_edit, null);
        addView(v, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        downloadTv = (TextView) v.findViewById(R.id.tv_download);
        deleteTv = (TextView) v.findViewById(R.id.tv_delete);
        shareTv = (TextView) v.findViewById(R.id.tv_share);
        downloadRl =  v.findViewById(R.id.rl_download);
        deleteRl = v.findViewById(R.id.rl_delete);
        shareRl =  v.findViewById(R.id.rl_share);
        downloadRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onEditListener == null)
                    return;
                onEditListener.download();
            }
        });
        deleteRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onEditListener == null)
                    return;
                onEditListener.delete();
            }
        });
        shareRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onEditListener == null)
                    return;
                onEditListener.share();
            }
        });

    }

    private OnEditListener onEditListener;

    public void setOnEditListener(OnEditListener onEditListenr) {
        if (onEditListenr == null)
            return;
        this.onEditListener = onEditListenr;
    }

    public void setEnable(boolean enable) {
        if (enable) {
            downloadTv.setBackgroundResource(R.mipmap.download_enable_true);
            deleteTv.setBackgroundResource(R.mipmap.delete_enable_true);
            shareTv.setBackgroundResource(R.mipmap.share_enable_true);
        } else {
            downloadTv.setBackgroundResource(R.mipmap.download_enable_false);
            deleteTv.setBackgroundResource(R.mipmap.delete_enable_false);
            shareTv.setBackgroundResource(R.mipmap.share_enable_false);
        }
        downloadRl.setEnabled(enable);
        deleteRl.setEnabled(enable);
        shareRl.setEnabled(enable);
    }

    public interface OnEditListener {

        void delete();

        void download();

        void share();

    }
}
